// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-11-15

#ifndef __SVR_MSGWND_H_COMMON_SVR_BASE__
#define __SVR_MSGWND_H_COMMON_SVR_BASE__

#pragma once

#include <common/base/thread.h>

namespace JoyServer
{

class CJoyMsgWndExec
{
public:
    virtual ~CJoyMsgWndExec()
    {
    }
    virtual void Execute() = 0;
};

class CJoyMsgWnd
{
protected:
    static LRESULT WINAPI sWindowProc(HWND hWnd, UINT nMessage, WPARAM wParam, LPARAM lParam);
    static PCSTR CJoyMsgWnd::GetWindowClass();

    HWND    m_hWnd;
    DWORD   m_threadId;


    CJoyCriticalSection m_lock;
    CList<CJoyMsgWndExec*>  m_execs;

    CList<CJoyMsgWndExec*>  m_tempExecs;

    void ProcessExecs();

    virtual void OnMessage(UINT nMessage, void* pContext);
public:
    CJoyMsgWnd();
    virtual ~CJoyMsgWnd();

    virtual bool Create();
    virtual void Destroy();

    void PostExec(CJoyMsgWndExec* exec);
};

} // namespace JoyServer

#endif  // __SVR_MSGWND_H_COMMON_SVR_BASE__